package thesis;
import org.bson.BSONObject;

import com.mongodb.BasicDBList;
import com.mongodb.DBObject;


public class InputTweetInfoExtractor extends TweetInfoExtractor{
	private DBObject tweet;
	
	public InputTweetInfoExtractor(DBObject tweet) {
		this.tweet = tweet;
	}
	
	public String getText(){
		String text = ((BSONObject)tweet.get("tweet")).get("text").toString();
		
		return text;
	}
	
	public long getId(){
		String id = ((BSONObject)tweet.get("tweet")).get("id").toString();
		
		return Long.parseLong(id);
	}
	
	public boolean containUrls(){
		BasicDBList urls = (BasicDBList)((BSONObject)((BSONObject)tweet.get("tweet")).get("entities")).get("urls");
		
		int urlsCount = urls.size();
		
		if (urlsCount == 0){
			return false;
		}
		else{
			return true;
		}
	}
	
	
	public boolean hasCoordinates(){
		Object geo = getCoordinates();
		
		if(geo != null){
			return true;
		}
		else{
			return false;
		}
	}
	
	public BasicDBList getCoordinates(){
		BSONObject geo = (BSONObject)((BSONObject)tweet.get("tweet")).get("geo");
		
		if (geo != null){
			BasicDBList coordinates = (BasicDBList)geo.get("coordinates");
			return coordinates;
		}
		else{
			return null;
		}
	}
	
	public Double getLatitude(){
		if (hasCoordinates()){
			BasicDBList coordinates = getCoordinates();
			double latitude = Double.parseDouble("" + coordinates.get(0));
			return latitude;
		}
		else{
			return null;
		}
	}
	
	public Double getLongitude(){
		if (hasCoordinates()){
			BasicDBList coordinates = getCoordinates();
			double longitude = Double.parseDouble("" + coordinates.get(1));
			return longitude;
		}
		else{
			return null;
		}
	}
	
	public long getTimestamp(){
		long timestamp = Long.parseLong((String)((BSONObject)tweet.get("header")).get("tweet_time"));
		
		return timestamp;
	}

	public double getUserListedCount() {
		int listedCount = (Integer)((BSONObject)((BSONObject)tweet.get("tweet")).get("user")).get("listed_count");
		
		return listedCount;
	}
}
